package com.knowledge.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;

import com.knowledge.common.annotation.Log;
import com.knowledge.common.core.controller.BaseController;
import com.knowledge.common.core.domain.AjaxResult;
import com.knowledge.common.enums.BusinessType;
import com.knowledge.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.knowledge.business.domain.TKeywords;
import com.knowledge.business.service.ITKeywordsService;
import com.knowledge.common.core.page.TableDataInfo;

/**
 * 关键词Controller
 *
 * @author zhaoyk
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/business/keywords")
public class TKeywordsController extends BaseController {
    @Autowired
    private ITKeywordsService tKeywordsService;

/**
 * 查询关键词列表
 */
//@RequiresPermissions("business:keywords:list")
@GetMapping("/list")
    public TableDataInfo list(TKeywords tKeywords) {
        startPage();
        List<TKeywords> list = tKeywordsService.selectTKeywordsList(tKeywords);
        return getDataTable(list);
    }

    /**
     * 导出关键词列表
     */
    //@RequiresPermissions("business:keywords:export")
    @Log(title = "关键词", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TKeywords tKeywords) {
        List<TKeywords> list = tKeywordsService.selectTKeywordsList(tKeywords);
        ExcelUtil<TKeywords> util = new ExcelUtil<TKeywords>(TKeywords. class);
        util.exportExcel(response, list, "关键词数据");
    }

    /**
     * 获取关键词详细信息
     */
    //@RequiresPermissions("business:keywords:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(tKeywordsService.getById(id));
    }

    /**
     * 新增关键词
     */
    //@RequiresPermissions("business:keywords:add")
    @Log(title = "关键词", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TKeywords tKeywords) {
        return toAjax(tKeywordsService.save(tKeywords));
    }

    /**
     * 修改关键词
     */
    //@RequiresPermissions("business:keywords:edit")
    @Log(title = "关键词", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TKeywords tKeywords) {
        return toAjax(tKeywordsService.updateById(tKeywords));
    }

    /**
     * 删除关键词
     */
    //@RequiresPermissions("business:keywords:remove")
    @Log(title = "关键词", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tKeywordsService.removeByIds(Arrays.asList(ids)));
    }
}
